将光标移动到屏幕上的任意 x
列 y
行并绘制 sprite
.
(defun drawxy (x y sprite)
(erase-buffer)
(insert-char ?\n y)
(insert-char ?\s x)
(insert sprite))
使用 insert-char
用于创建空格. ?\s
是空格字符的编码。
使用 insert-char
可以指定要插入的字符数,并且不需要 dotimes
循环。
(defun background (width height) (erase-buffer) (dotimes (i height) (insert-char ?\. width) (newline)))
使用 insert-char
绘制网格,保存一个 dotimes
循环。
这将绘制一个由句号组成的网格(通过 ?\.
字符编码)。
可以用 ?\s
替换 ?\.
来画一个看不见的网格。
无论哪种方式,目标都是创建一个光标移动的空间,在不必擦除缓冲区的情况下绘制多个Sprint。
(defun drawxy2 (x y sprite)
(goto-char 1)
(forward-line y)
(forward-char x)
(delete-region (point) (+ (point) (length sprite)))
(insert sprite))
background
和 drawxy2
需要预先执行
(defun where ()
(background 40 25)
(dotimes (i 10)
(if (= i 5)
(drawxy2 30 i "here")
(drawxy2 (* i 3) (* i 2) "there?"))
(sit-for 0.2)))
background
和 drawxy2
也需要预先执行
(defun where2 ()
(background 40 25)
(dotimes (i 20)
(if (= i 12)
(drawxy2 30 i (propertize "here" 'face '(:foreground "green")))
(drawxy2 (random 30) (random 25) "there?"))
(sit-for 0.2)))